package cn.lbwfree.web.controller;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

import cn.lbwfree.web.entity.Admin;
import cn.lbwfree.web.entity.Reader;

@WebServlet(name = "IndexServlet",urlPatterns = "")
public class IndexServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session = request.getSession();
        Reader reader = (Reader) session.getAttribute("reader");
        Admin admin = (Admin) session.getAttribute("admin");
        if(reader != null || admin != null){
            request.getRequestDispatcher("index.jsp").forward(request,response);
        }else{
            request.getRequestDispatcher("login.jsp").forward(request,response);
        }

    }
}
